package th.stripes.resources;

import com.google.inject.Inject;
import java.io.BufferedReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import net.sourceforge.stripes.action.ErrorResolution;
import net.sourceforge.stripes.action.HandlesEvent;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.action.UrlBinding;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import th.config.ableContextListener;
import th.manager.AkaunManager;
import th.manager.UserManager;
import th.model.Akaun;
import th.model.Deposit;
import th.model.Haji;
import th.model.KodNegeri;
import th.dao.KodNegeriDAO;
import th.dao.KodPekerjaanDAO;
import th.model.KodPekerjaan;
import th.model.Pengguna;
import th.service.session.LoginSession;
import th.service.session.SessionManager;
import th.stripes.BaseActionBean;
import th.stripes.services.HajiService;
import th.stripes.util.AccCheckUtil;



/*
 *
 * @author yogendra
 */

@UrlBinding("/services/haji")
public class HajiResource extends BaseActionBean implements iRest{
    
    private Deposit deposit;
    private Haji haji;
    private String status;
    private static final Logger LOG = Logger.getLogger(HajiService.class);
    @Inject
     private UserManager userManager;

    @Inject
     private AkaunManager akaunManager;
    
    @Inject
     private KodNegeriDAO kodNegeriDAO;
    
    @Inject
     private KodPekerjaanDAO kodPekerjaanDAO;
    
    
    @HandlesEvent("check_hajj_offer")
     public Resolution checkHajjOffer() {

          String line = null;

          StringBuilder sb = new StringBuilder();

          String id = getContext().getRequest().getHeader("Cookie");
          id = id.substring(id.indexOf("=") + 1);

          BufferedReader reader = null;
          try {

               reader = getContext().getRequest().getReader();
               while ((line = reader.readLine()) != null) {
                    sb.append(line);
               }

               if (sb.length() > 0) {
                    JSONObject json = new org.json.JSONObject(sb.toString());
                    HajiService service = ableContextListener.newInstance(HajiService.class);
                    haji = new Haji();
                    haji.setNoAkaun(json.getString("noAkaun") != null ? json.getString("noAkaun") : null);
                    haji.setNoKp(json.getString("noKp") != null ? json.getString("noKp") : null);
                    haji.setNoAkaunDari(json.getString("noAkaunDari") != null ? json.getString("noAkaunDari") : null);
                    haji.setNoKpDari(json.getString("noKpDari") != null ? json.getString("noKpDari") : null);

                    AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);

                    boolean check = checking.checkAcc(haji, id);

                    if (!check) {
                         return new ErrorResolution(401);
                    }

                    String idSessi = getContext().getRequest().getSession().getId();

                    service.hajjOfferEnq(haji, checking.getPengguna(), status, idSessi);
                    
                    JSONObject obj = new JSONObject();
                    
                    obj.put("nama", haji.getNama());
                    obj.put("noAkaun", haji.getNoAkaun());
                    obj.put("noKp", haji.getNoKp());
                    obj.put("tahunTawaran", haji.getTahunTawaran());
                    obj.put("tahunTawaranHijrah", haji.getTahunTawaranHijrah());
                    obj.put("tahunTarikhTawaran", haji.getTarikhTawaran());
                    obj.put("tarikhTutupTawaran", haji.getTarikhTutupTawaran());
                    obj.put("pusatKos", haji.getPusatKos().getKod());
                    obj.put("statusTawaran", haji.getStatusTawaran());
                    obj.put("noTel", haji.getNoTelTHCC());
                    
                    if (haji.getStatusHaji() == null) {
                       //  return new JSP("haji/pertanyaan_tawaran_haji_detail.jsp");
                    } else if (haji.getStatusHaji().getKod().equalsIgnoreCase("G")) {
                       // addSimpleMessage("TUAN / PUAN TELAH MENOLAK TAWARAN");
                       obj.put("statusHaji", "TUAN / PUAN TELAH MENOLAK TAWARAN");
                    } 
                    
                    
                    
                    return new StreamingResolution("application/json", obj.toString());
               }

          } catch (IOException e) {
               LOG.error(e);

          } finally {
               try {
                    if (reader != null) {
                         reader.close();
                    }
               } catch (IOException ex) {
               }
          }

          return new ErrorResolution(401);
     }
    

    @HandlesEvent("registration")
     public Resolution pendaftaranHaji() {
  
        String line = null;
        
        StringBuilder sb = new StringBuilder();
        
        String id = getContext().getRequest().getHeader("Cookie");    
        id = id.substring(id.indexOf("=")+1);
        
        BufferedReader reader = null;
        try {
            
            reader = getContext().getRequest().getReader();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            
            if (sb.length() > 0) {
                JSONObject json = new org.json.JSONObject(sb.toString());
                HajiService service = ableContextListener.newInstance(HajiService.class);
                haji = new Haji();
                haji.setNoAkaun( json.getString("noAkaun") != null ?  json.getString("noAkaun") : null);
                haji.setNoKp( json.getString("noKP") != null ?  json.getString("noKP") : null );
                haji.setNoKpDari(json.getString("noKPDari") != null ?  json.getString("noKPDari") : null );
                haji.setNoAkaunDari(json.getString("noAkaunDari") != null ?  json.getString("noAkaunDari") : null);
                
                
                 AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
                 
                 boolean check = checking.checkAcc(haji, id);
                 
                 if (!check) {
                     return new ErrorResolution(401);
                 }                
                
                String idSessi = getContext().getRequest().getSession().getId();
                
                service.pendaftaranHaji(haji, checking.getPengguna(), status, idSessi);

                
                return new StreamingResolution("application/json", toJson());
            }
            
            
        } catch (IOException e) { 
            LOG.error(e);
            
        }finally{
            try {
                if (reader != null) reader.close();
            } catch (IOException ex) {
            }
        }

        return new ErrorResolution(401);
    }
    
    @HandlesEvent("step2")
     public Resolution saveRegistration() {
  
        String line = null;
        
        StringBuilder sb = new StringBuilder();
        
        String id = getContext().getRequest().getHeader("Cookie");    
        id = id.substring(id.indexOf("=")+1);
        
        BufferedReader reader = null;
        try {
            
            reader = getContext().getRequest().getReader();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            
            if (sb.length() > 0) {
                JSONObject json = new org.json.JSONObject(sb.toString());
                HajiService service = ableContextListener.newInstance(HajiService.class);
                haji = new Haji();
                haji.setNoAkaun( json.getString("noAkaun") != null ?  json.getString("noAkaun") : null);
                haji.setNoKp( json.getString("noKP") != null ?  json.getString("noKP") : null );
                haji.setNoKpDari(json.getString("noKPDari") != null ?  json.getString("noKPDari") : null );
                haji.setNoAkaunDari(json.getString("noAkaunDari") != null ?  json.getString("noAkaunDari") : null);
                
                
                 AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
                 
                 boolean check = checking.checkAcc(haji, id);
                 
                 if (!check) {
                     return new ErrorResolution(401);
                 }                
                
                String idSessi = getContext().getRequest().getSession().getId();
                
                service.savePendaftaranHaji(haji, checking.getPengguna(), status, idSessi);

                
                return new StreamingResolution("application/json", toJson());
            }
            
            
        } catch (IOException e) { 
            LOG.error(e);
            
        }finally{
            try {
                if (reader != null) reader.close();
            } catch (IOException ex) {
            }
        }

        return new ErrorResolution(401);
    }
    
    @HandlesEvent("step3")
     public Resolution addNewMembers() {
  
        String line = null;
        
        StringBuilder sb = new StringBuilder();
        
        String id = getContext().getRequest().getHeader("Cookie");    
        id = id.substring(id.indexOf("=")+1);
        
        BufferedReader reader = null;
        try {
            
            reader = getContext().getRequest().getReader();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            
            if (sb.length() > 0) {
                JSONObject json = new org.json.JSONObject(sb.toString());
                HajiService service = ableContextListener.newInstance(HajiService.class);
                haji = new Haji();
                haji.setNoAkaun( json.getString("noAkaun") != null ?  json.getString("noAkaun") : null);
                haji.setNoKp( json.getString("noKP") != null ?  json.getString("noKP") : null );
                haji.setNoKpDari(json.getString("noKPDari") != null ?  json.getString("noKPDari") : null );
                haji.setNoAkaunDari(json.getString("noAkaunDari") != null ?  json.getString("noAkaunDari") : null);
                
                
                 AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
                 
                 boolean check = checking.checkAcc(haji, id);
                 
                 if (!check) {
                     return new ErrorResolution(401);
                 }                
                
                String idSessi = getContext().getRequest().getSession().getId();
                
                service.pendaftaranHaji(haji, checking.getPengguna(), status, idSessi);

                
                return new StreamingResolution("application/json", toJson());
            }
            
            
        } catch (IOException e) { 
            LOG.error(e);
            
        }finally{
            try {
                if (reader != null) reader.close();
            } catch (IOException ex) {
            }
        }

        return new ErrorResolution(401);
    }
    
    @HandlesEvent("step4")
     public Resolution checkAccount() {
  
        String line = null;
        
        StringBuilder sb = new StringBuilder();
        
        String id = getContext().getRequest().getHeader("Cookie");    
        id = id.substring(id.indexOf("=")+1);
        
        BufferedReader reader = null;
        try {
            
            reader = getContext().getRequest().getReader();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            
            if (sb.length() > 0) {
                JSONObject json = new org.json.JSONObject(sb.toString());
                HajiService service = ableContextListener.newInstance(HajiService.class);
                haji = new Haji();
                haji.setNoAkaun( json.getString("noAkaun") != null ?  json.getString("noAkaun") : null);
                haji.setNoKp( json.getString("noKP") != null ?  json.getString("noKP") : null );
                haji.setNoKpDari(json.getString("noKPDari") != null ?  json.getString("noKPDari") : null );
                haji.setNoAkaunDari(json.getString("noAkaunDari") != null ?  json.getString("noAkaunDari") : null);
                
                
                 AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
                 
                 boolean check = checking.checkAcc(haji, id);
                 
                 if (!check) {
                     return new ErrorResolution(401);
                 }                
                
                String idSessi = getContext().getRequest().getSession().getId();
                
                service.pendaftaranHaji(haji, checking.getPengguna(), status, idSessi);

                
                return new StreamingResolution("application/json", toJson());
            }
            
            
        } catch (IOException e) { 
            LOG.error(e);
            
        }finally{
            try {
                if (reader != null) reader.close();
            } catch (IOException ex) {
            }
        }

        return new ErrorResolution(401);
    }
    
    @HandlesEvent("step5")
     public Resolution saveNewMembers() {
  
        String line = null;
        
        StringBuilder sb = new StringBuilder();
        
        String id = getContext().getRequest().getHeader("Cookie");    
        id = id.substring(id.indexOf("=")+1);
        
        BufferedReader reader = null;
        try {
            
            reader = getContext().getRequest().getReader();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            
            if (sb.length() > 0) {
                JSONObject json = new org.json.JSONObject(sb.toString());
                HajiService service = ableContextListener.newInstance(HajiService.class);
                haji = new Haji();
                haji.setNoAkaun( json.getString("noAkaun") != null ?  json.getString("noAkaun") : null);
                haji.setNoKp( json.getString("noKP") != null ?  json.getString("noKP") : null );
                haji.setNoKpDari(json.getString("noKPDari") != null ?  json.getString("noKPDari") : null );
                haji.setNoAkaunDari(json.getString("noAkaunDari") != null ?  json.getString("noAkaunDari") : null);
                
                
                 AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
                 
                 boolean check = checking.checkAcc(haji, id);
                 
                 if (!check) {
                     return new ErrorResolution(401);
                 }                
                
                String idSessi = getContext().getRequest().getSession().getId();
                
                service.pendaftaranHaji(haji, checking.getPengguna(), status, idSessi);

                
                return new StreamingResolution("application/json", toJson());
            }
            
            
        } catch (IOException e) { 
            LOG.error(e);
            
        }finally{
            try {
                if (reader != null) reader.close();
            } catch (IOException ex) {
            }
        }

        return new ErrorResolution(401);
    }
    
    @HandlesEvent("req_all_akauns")
     public Resolution getAllAkauns() {

          String sessionId = getContext().getRequest().getParameter("sessionId");

          String userId = getContext().getRequest().getParameter("userId");

          SessionManager sm = SessionManager.getInstance();

          LoginSession ls = sm.getActiveSessionByUserId(userId);

          if (ls != null && ls.getSessionId().equals(sessionId)) {
               Pengguna pengguna = userManager.findUserByIdUser(userId);
               if (pengguna != null) {
                    return new StreamingResolution("application/json",
                            toJsonList(pengguna.getSenaraiAkaun()));
               }
          }

          return new ErrorResolution(401, "Tiada Akaun");
     }

     @HandlesEvent("req_noKp")
     public Resolution getNoKP() {

          String sessionId = getContext().getRequest().getParameter("sessionId");

          String userId = getContext().getRequest().getParameter("userId");

          String noAkaun = getContext().getRequest().getParameter("noAkaun");

          SessionManager sm = SessionManager.getInstance();

          LoginSession ls = sm.getActiveSessionByUserId(userId);

          if (ls != null && ls.getSessionId().equals(sessionId)) {
               String noKP = akaunManager.getNoPengenalan(noAkaun);
               if (StringUtils.isNotBlank(noKP)) {
                    JSONObject obj = new JSONObject();
                    obj.put("noKP", noKP);
                    return new StreamingResolution("application/json", obj.toString());
               }
          }

          return new ErrorResolution(401, "Tiada No KP");
     }
    
    /**
     *
     * @return
     */
    @HandlesEvent("checkRegistration")
     public Resolution semakPendaftaranHaji() {
  
        String line = null;
        
        StringBuilder sb = new StringBuilder();
          
        String id = getContext().getRequest().getHeader("Cookie");    
        id = id.substring(id.indexOf("=")+1);
        
        BufferedReader reader = null;
        try {
             
            reader = getContext().getRequest().getReader();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            
            if (sb.length() > 0) {
                JSONObject json = new org.json.JSONObject(sb.toString());
                HajiService service = ableContextListener.newInstance(HajiService.class);
                haji = new Haji();
                haji.setNoAkaun( json.getString("noAkaun") != null ?  json.getString("noAkaun") : null);
                haji.setNoKp( json.getString("noKP") != null ?  json.getString("noKP") : null );
                haji.setNoAkaunDari(json.getString("noAkaunDari") != null ?  json.getString("noAkaunDari") : null);
                haji.setNoKpDari(json.getString("noKPDari") != null ?  json.getString("noKPDari") : null );
                
                 AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
        
                 boolean check = checking.checkAcc(haji, id);
                 
                 if (!check) {
                     return new StreamingResolution("text/plain", "NO AKAUN / PENGENALAN TIDAK SAH!!");
                 }                
                
                String idSessi = getContext().getRequest().getSession().getId();
                
                service.semakPendaftaranHaji(haji, checking.getPengguna(), status, idSessi);
          
                
                return new StreamingResolution("application/json", toJson());
            }
            
        } catch (IOException e) { 
            LOG.error(e);
            
        }finally{
            try {
                if (reader != null) reader.close();
            } catch (IOException ex) {
            }
        }

        return new ErrorResolution(401);
    }
    
    @HandlesEvent("printSlip")
     public Resolution cetakSlipPendaftaran() {

        String line = null;
        
        StringBuilder sb = new StringBuilder();
        
        String id = getContext().getRequest().getHeader("Cookie");    
        id = id.substring(id.indexOf("=")+1);
        
        BufferedReader reader = null;
        try {
           
            reader = getContext().getRequest().getReader();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            
            if (sb.length() > 0) {
                JSONObject json = new org.json.JSONObject(sb.toString());
                HajiService service = ableContextListener.newInstance(HajiService.class);
                haji = new Haji();
                haji.setNoAkaun( json.getString("noAkaun") != null ?  json.getString("noAkaun") : null);
                haji.setNoKp( json.getString("noKP") != null ?  json.getString("noKP") : null );
                haji.setNoAkaunDari(json.getString("noAkaunDari") != null ?  json.getString("noAkaunDari") : null);
                haji.setNoKpDari(json.getString("noKPDari") != null ?  json.getString("noKPDari") : null );
                
                 AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
        
                 boolean check = checking.checkAcc(haji, id);
                 
                 if (!check) {
                     return new StreamingResolution("text/plain", "NO AKAUN / PENGENALAN TIDAK SAH!!");
                 }                
                
                String idSessi = getContext().getRequest().getSession().getId();
                
                service.cetakSlipPendaftaran(haji, checking.getPengguna(), status, idSessi);
         
                return new StreamingResolution("application/json", toJson());
            }
            
            
        } catch (IOException e) { 
            LOG.error(e);
            
        }finally{
            try {
                if (reader != null) reader.close();
            } catch (IOException ex) {
            }
        }

        return new ErrorResolution(401);
    }
    
    @HandlesEvent("flightSchedule")
     public Resolution cetakJadualPenerbangan() {

        String line = "";
        
        StringBuilder sb = new StringBuilder();
        
        String id = getContext().getRequest().getHeader("Cookie");    
        id = id.substring(id.indexOf("=")+1);
        
        BufferedReader reader = null;
        try {
            
            reader = getContext().getRequest().getReader();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            
            if (sb.length() > 0) {
                JSONObject json = new org.json.JSONObject(sb.toString());
                haji = new Haji();
                HajiService service = ableContextListener.newInstance(HajiService.class);
                haji.setNoAkaun( json.getString("noAkaun") != null ?  json.getString("noAkaun") : null);
                haji.setNoKp( json.getString("noKP") != null ?  json.getString("noKP") : null );
                haji.setNoAkaunDari(json.getString("noAkaunDari") != null ?  json.getString("noAkaunDari") : null);
                haji.setNoKpDari(json.getString("noKPDari") != null ?  json.getString("noKPDari") : null );
                
                 AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
        
                 boolean check = checking.checkAcc(haji, id);
                 
                 if (!check) {
                     return new ErrorResolution(401);
                 }                
                
                String idSessi = getContext().getRequest().getSession().getId();
                
                service.cetakJadualPenerbangan(haji, checking.getPengguna(), status, idSessi);

                
                return new StreamingResolution("application/json", toJson());
            }
            
            
        } catch (IOException e) { 
            LOG.error(e);
            
        }finally{
            try {
                if (reader != null) reader.close();
            } catch (IOException ex) {
            }
        }

        return new ErrorResolution(401);
    }
     
     public void parseFromJson(Haji haji, JSONObject json) throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
         haji.setNoAkaun                 ((String)                 json.get("noAkaun"));
         haji.setNoKp                    ((String)                 json.get("noKp"));
         haji.setNoAkaunDari             ((String)                 json.get("dariAkaun"));
         haji.setNoKpDari                ((String)                 json.get("noKpDari"));
         haji.setNama                    ((String)                 json.get("nama"));
         haji.setAlamat1                 ((String)                 json.get("alamat1"));
         haji.setAlamat2                 ((String)                 json.get("alamat2"));
         haji.setAlamat3                 ((String)                 json.get("alamat3"));
         haji.setPoskod                  ((String)                 json.get("poskod"));
         haji.setNoTel1                  ((String)                 json.get("noTel1"));
         haji.setNoTel2                  ((String)                 json.get("noTel2"));
         haji.setNoTel3                  ((String)                 json.get("noTel3"));
         haji.setFax                     ((String)                 json.get("fax"));
         haji.setTmtLahir                ((String)                 json.get("tmtLahir"));
         haji.setNoDaftar                ((String)                 json.get("noDaftar"));
         haji.setNoRujukan               ((String)                 json.get("noRujukan"));
         haji.setTahunPeruntukanHijrah   ((String)                 json.get("tahunPeruntukanHijrah"));
         haji.setNoTelTHCC               ((String)                 json.get("noTelTHCC"));
         haji.setNoKt                    ((String)                 json.get("noKt"));
         haji.setCheckInPlace            ((String)                 json.get("checkInPlace"));
         haji.setLaporDiriBalik          ((String)                 json.get("laporDiriBalik"));
         haji.setCheckInTimePhase1       ((String)                 json.get("checkInTimePhase1"));
         haji.setCheckInDay              ((String)                 json.get("checkInDay"));
         haji.setMasaBalik               ((String)                 json.get("masaBalik"));
         haji.setNoPesawatPergi          ((String)                 json.get("noPesawatPergi"));
         haji.setNoPesawatBalik          ((String)                 json.get("noPesawatBalik"));
         haji.setRetFinal                ((String)                 json.get("retFinal"));
         haji.setWaktuTiba               ((String)                 json.get("waktuTiba"));
         haji.setDestinasiPergi          ((String)                 json.get("destinasiPergi"));
         haji.setMiqatDi                 ((String)                 json.get("miqatDi"));
          
         String kodNegeri = (String)json.getString("negeri");
           if(StringUtils.isNotBlank(kodNegeri)){
              KodNegeri negeri = kodNegeriDAO.findById(kodNegeri);
              haji.setNegeri(negeri);
           }
            
         String kodPekerjaan = (String)json.getString("pekerjaan");
           if(StringUtils.isNotBlank(kodPekerjaan)){
              KodPekerjaan pekerjaan = kodPekerjaanDAO.findById(kodPekerjaan);
              haji.setPekerjaan(pekerjaan);
           }

         haji.setTarikhDaftar            ((Date)                 json.get("tarikhDaftar"));
         haji.setTarikhPergi             ((Date)                 json.get("tarikhPergi"));
         haji.setTarikhLaporDiriBalik    ((Date)                 json.get("tarikhLaporDiriBalik"));
         haji.setTarikhTiba              ((Date)                 json.get("tarikhTiba"));
         
     } 
    
     

    public String toJson() {
        
        JSONObject obj = new JSONObject();
        
        if (haji != null){
        
        obj.put("noAkaun",haji.getNoAkaun());
        obj.put("noKp", haji.getNoKp());
        obj.put("noKpDari", haji.getNoKpDari());
        obj.put("noAkaunDari",haji.getNoAkaunDari());
        obj.put("nama", haji.getNama());
        obj.put("alamat1", haji.getAlamat1());
        obj.put("alamat2", haji.getAlamat2());
        obj.put("alamat2", haji.getAlamat3());
        obj.put("noTel1", haji.getNoTel1());
        obj.put("noTel2", haji.getNoTel2());
        obj.put("noTel3", haji.getNoTel3());
        obj.put("fax", haji.getFax());
        obj.put("negeri", haji.getNegeri());
        obj.put("tmtlahir", haji.getTmtLahir());
        obj.put("pekerjaan",haji.getPekerjaan());
        obj.put("noKt",haji.getNoKt());
        obj.put("checkInPlace", haji.getCheckInPlace());
        obj.put("laporDiriBalik", haji.getLaporDiriBalik());
        obj.put("tarikhPergi",haji.getTarikhPergi());
        obj.put("tarikhLaporDiriBalik", haji.getLaporDiriBalik());
        obj.put("checkInTimePhase1", haji.getCheckInTimePhase1());
        obj.put("checkInDay", haji.getCheckInDay());
        obj.put("masaBalik", haji.getMasaBalik());
        obj.put("noPesawatPergi", haji.getNoPesawatPergi());
        obj.put("noPesawatBalik",haji.getNoPesawatBalik());
        obj.put("tarikhTiba", haji.getTarikhTiba());
        obj.put("retFinal", haji.getRetFinal());
        obj.put("waktuTiba", haji.getWaktuTiba());
        obj.put("destinasiPergi", haji.getDestinasiPergi());
        obj.put("miqatDi", haji.getMiqatDi());
        obj.put("noRujukan", haji.getNoRujukan());
        obj.put("tahunPeruntukanHijrah", haji.getTahunPeruntukanHijrah());
        obj.put("tahunPeruntukan", haji.getTahunPeruntukan());
        obj.put("tarikhDaftar", haji.getTarikhDaftar());
        obj.put("pusatKosDeskripsi", haji.getPusatKosDeskripsi());
        obj.put("noTelTHCC", haji.getNoTelTHCC());
        
        }
        
        return obj.toString();

    }

    public String toJsonList(List<Akaun> akauns) {
          JSONArray array = new JSONArray();

          for (Akaun akaun : akauns) {
               JSONObject obj = new JSONObject();
               obj.put("akaunTmbhn", akaun.getAkaunTmbhn());
               obj.put("noPengenalanTmbhn", akaun.getNoPengenalanTmbhn());
               obj.put("nama", akaun.getNamaAkaunTmbhn());
               array.put(obj);
          }

          return array.toString();
     }
    
    public Haji getHaji() {
        return haji;
    }

    public void setHaji(Haji haji) {
        this.haji = haji;
    }
    
}
